<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Entity;

class Room
{
    protected int $room_id = 0;

    protected array $players = [];

    protected array $user_fds = [];

    public function getRoomId()
    {
        return $this->room_id;
    }

    public function setRoomId(int $roomId)
    {
        $this->room_id = $roomId;
    }

    public function setPlayer(int $userId)
    {
        $this->players[] = $userId;
    }

    public function removePlayer(int $userId)
    {
        foreach ($this->players as $index => $player) {
            if ($userId == $player) {
                array_splice($this->players, $index, 1);
            }
        }
    }

    public function setUserFd(int $userId, int $fd)
    {
        $this->user_fds[$userId] = $fd;
    }

    public function getFds()
    {
        return array_values($this->user_fds);
    }
}
